home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 September / PCWorld_2008-09_cd.bin / v cisle / sadanastroju / wot-20080519-fx.xpi / chrome / wot.jar / content / api / link.js next >
Text File  |  2008-02-21  |  2KB  |  106 lines

  1. /*
  2.     api/link.js
  3.  
  4.     Copyright ┬⌐ 2006, 2007  Against Intuition, Inc. <info@mywot.com>
  5. */
  6.  
  7. var wot_api_link =
  8. {
  9.     init: function()
  10.     {
  11.     },
  12.  
  13.     send: function(rule, content, cache)
  14.     {
  15.         try {
  16.             if (!wot_api_register.ready) {
  17.                 return;
  18.             }
  19.  
  20.             var i, j = 0, hosts = "";
  21.             var nonce = wot_crypto.nonce();
  22.  
  23.             for (i in cache) {
  24.                 if (cache[i] != i ||
  25.                         (wot_cache.iscached(i) && (wot_cache.get(i, "pending") ||
  26.                          wot_cache.get(i, "inprogress")))) {
  27.                     continue;
  28.                 }
  29.  
  30.                 if ((hosts.length + i.length + 1) > WOT_MAX_LINK_HOSTSLEN) {
  31.                     break;
  32.                 }
  33.  
  34.                 hosts += i + "/";
  35.                 wot_cache.add_nonce(nonce + "-" + j++, i);
  36.  
  37.                 if (j >= WOT_MAX_LINK_PARAMS) {
  38.                     break;
  39.                 }
  40.             }
  41.  
  42.             if (hosts.length == 0) {
  43.                 return;
  44.             }
  45.  
  46.             var context =
  47.                 wot_arc4.create(wot_hash.hmac_sha1hex(wot_prefs.witness_key,
  48.                     nonce));
  49.  
  50.             if (!context) {
  51.                 return;
  52.             }
  53.  
  54.             var crypted_hosts =
  55.                 wot_arc4.crypt(context, wot_hash.strtobin(hosts));
  56.  
  57.             if (!crypted_hosts) {
  58.                 return;
  59.             }
  60.  
  61.             var query_string = WOT_SERVICE_API_LINK +
  62.                 "?id="        + wot_prefs.witness_id +
  63.                 "&nonce="    + nonce +
  64.                 "&hosts="    + encodeURIComponent(btoa(
  65.                                 wot_hash.bintostr(crypted_hosts))) +
  66.                 "&lang="    + wot_util.getstring("language") +
  67.                 "&version="    + WOT_PLATFORM + "-" + WOT_VERSION;
  68.  
  69.             var request = new XMLHttpRequest();
  70.  
  71.             request.open("GET", WOT_SERVICE_NORMAL +
  72.                 wot_crypto.authenticate_query(query_string));
  73.  
  74.             new wot_cookie_remover(request);
  75.  
  76.             request.onload = function(event)
  77.             {
  78.                 try {
  79.                     if (request.status == 200) {
  80.                         wot_cache.add_query(
  81.                             request.responseXML.getElementsByTagName(
  82.                                 WOT_SERVICE_XML_LINK),
  83.                             request.responseXML.getElementsByTagName(
  84.                                 WOT_SERVICE_XML_QUERY_TARGET),
  85.                             true);
  86.                     }
  87.  
  88.                     wot_search.update(rule, content, cache, true);
  89.  
  90.                     for (var i = 0; i < j; ++i) {
  91.                         wot_cache.remove_nonce(nonce + "-" + i);
  92.                     }
  93.                 } catch (e) {
  94.                     dump("wot_api_link.onload: failed with " + e + "\n");
  95.                 }
  96.             }
  97.  
  98.             request.send(null);
  99.         } catch (e) {
  100.             dump("wot_api_link.send: failed with " + e + "\n");
  101.         }
  102.     }
  103. };
  104.  
  105. wot_api_link.init();
  106.